package com.tomatozq.redis.controller;

import com.tomatozq.redis.vo.EquipmentVO;
import com.tomatozq.redis.vo.UserVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.concurrent.CountDownLatch;

@Controller
public class HelloController {
    @RequestMapping("/")
    public String index(Model model){
        model.addAttribute("welcome","hello world!");


        return "index";
    }

    @RequestMapping("/redDates/equipInfo")
    @ResponseBody
    public String equipInfo(@RequestBody EquipmentVO equipmentVO){
        return equipmentVO.getEquipCode() + "," + equipmentVO.getSign();
    }

    @RequestMapping("/ognl")
    public String ognl(Model model,HttpSession session){
        model.addAttribute("user",new UserVO("tomato","zq","China"));

        model.addAttribute("sessionId",session.getId());

        if(session.getAttribute("time")==null){
            session.setAttribute("time",System.currentTimeMillis());
        }

        return "ognl";
    }

    public static void main(String[] args) {
        CountDownLatch latch = new CountDownLatch(2);

        try {
            System.out.println("await");

            latch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("end!");
    }
}
